<script setup>
import { inject, ref } from 'vue';

const {addstu} = inject("student")
// 创建一个ref储存新的学生信息
const newstu = ref(
    {
        name: "",
        age: "",
        gender: "男",
        address: ""
    }
)



const submit = () => {
    addstu({...newstu.value})
    // console.log(newstu.value)
    newstu.value.name = ""
    newstu.value.age = ""
    newstu.value.gender = "男"
    newstu.value.address = ""
}

</script>

<template>
    <form @submit.prevent="submit">
        <div>
            姓名：<input type="text" v-model="newstu.name">
        </div>
        <div>
            年龄：<input type="number" min="1" v-model="newstu.age">
        </div>
        <div>
            性别：
            <input type="radio" value="男" v-model="newstu.gender">男
            <input type="radio" value="女" v-model="newstu.gender">女
        </div>
        <div>
            地址：<input type="text" v-model="newstu.address">
        </div>
        <div>
            <button>点击添加</button>
        </div>
    </form>
</template>